<?php
/**
 * Created by INGEPHP CURD.
 * User:
 * Date: 2018/10/17
 * Time: 10:17
 */

namespace app\admin\controller;

use app\common\controller\Admin;
use think\facade\Request;
use app\common\facade\Addons;

class AddonsController extends Admin
{

    /**
     * 列表方法
     * @method get
     * @param int $page 页码
     * @param int $limit 每页数量
     * @param string $keyword 关键词
     * @return json
     */
    public function index()
    {
        $keyword = Request::param('keyword', '');
        $res = Addons::getList($keyword);
        return $this->results($res);
    }


//    /**
//     * 根据ID获取插件配置
//     * @method get
//     * @param int $id 获取的id
//     * @return json
//     */
//    public function getOptions($d_id)
//    {
//        return $this->results(Addons::getAddonsOptions($d_id));
//    }

    /**
     * 根据ID获取更新配置
     * @method get
     * @param int $id 获取的id
     * @return json
     */
    public function updateOptions($d_id)
    {
        $data = Request::except('d_id');
        return $this->results(Addons::updateOptions($d_id, $data));
    }

    /**
     * 根据ID开启或关闭插件
     * @method get
     * @param int $id
     * @return json
     */
    public function toggle($d_id)
    {
        return $this->results(Addons::toggle($d_id));
    }

    /**
     * 安装插件
     * @method get
     * @param int $id
     * @return json
     */
    public function install($d_id)
    {
        return $this->results(Addons::install($d_id));
    }

    /**
     * 卸载插件
     * @method get
     * @param int $id
     * @return json
     */
    public function uninstall($d_id)
    {
        return $this->results(Addons::uninstall($d_id));
    }
}